﻿using DoNetDrive.Core;
using DoNetDrive.Core.Connector;
using DoNetDrive.Core.Factory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace DoNetDrive.Connector.WindowsBLE
{
    public class BLEFactory : INConnectorFactory
    {

        public INConnector CreateConnector(INConnectorDetail cd, IConnecterManage ConnecterManage)
        {
            return new BLEConnector(cd as BLEDetail);
        }

        public async Task<INConnector> CreateConnectorAsync(INConnectorDetail cd, IConnecterManage ConnecterManage)
        {
            var ble = new BLEConnector(cd as BLEDetail);
            await ble.ConnectAsync();
            return ble;
        }
    }

    public static class BLEFactoryExtension
    {

        public static void AddBLEConnectorFactory(this ConnectorAllocator act)
        {
            //导入 串口通讯库
            var defFactory = act.ConnectorFactory as DefaultConnectorFactory;
            defFactory.ConnectorFactoryDictionary.Add(BLEDetail.BLETypeName, new BLEFactory());
        }


    }
}
